﻿using CuocChienQueNha.Class.Basic;
using CuocChienQueNha.Class.File;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;

namespace CuocChienQueNha.Class.MainMap
{
    class MiniMap : ButtonGame
    {
        private Texture2D imgStar, imgLock;
        private int curStar;
        public bool isOpen { get; set; }
        public MiniMap(string name, string link, Vector2 position, Vector2 size, float scale)
        {
            this.name = name;
            this.linkImg = link;
            this.position = position;
            this.size = size;
            this.scale = scale;
            isTouched = false;
            isEnable = true;
        }
        public override void Load(ContentManager content)
        {
            image = content.Load<Texture2D>(linkImg);
            imgStar = content.Load<Texture2D>("Images/MainMap/star");
            imgLock = content.Load<Texture2D>("Images/MainMap/Lock");
        }
        public void Draw(SpriteBatch sprite, Vector2 dolech)
        {
            sprite.Draw(image, position - (isTouched ? new Vector2(size.X / 2, size.Y) * 0.1f : Vector2.Zero) + dolech, new Rectangle(0, 0, (int)size.X / 2, (int)size.Y), Color.White, 0f, Vector2.Zero, (isTouched ? scale + 0.2f : scale), SpriteEffects.None, 0);
            if (!isOpen)
            {
                sprite.Draw(imgLock, position + new Vector2(100, 60) + dolech, new Rectangle(0, 0, 82, 99), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0);
            }
            else
            {
                for (int i = 1; i <= curStar; i++)
                    sprite.Draw(imgStar, position + (isTouched ? new Vector2(47 + 41 * i, 196) : new Vector2(57 + 35 * i, 180)) + dolech, new Rectangle(0, 0, 32, 32), Color.White, 0f, Vector2.Zero, 0.8f, SpriteEffects.None, 0);
            }
        }
        public bool isTouch(Vector2 touch, Vector2 dolech)
        {
            touch -= dolech;
            return isTouch(touch);
        }
        public void setElement(LevelStruct levels)
        {
            curStar = levels.star;
            isOpen = levels.isOpen;
        }
    }
}
